﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using BibMan.model.database.bibtex;
using BibMan.util;

namespace BibMan.model.database.Referencer {
    [Serializable]
    [XmlType("library")]
    public class JabLibrary : JabRefItem {

        [XmlArray("taglist")]
        public List<JabTag> Tags { get; set; }
        [XmlArray("doclist")]
        public List<JabDoc> Docs { get; set; }
        
        public JabLibrary() {
            //initialize all
        }

        public override String ToString() {
            StringBuilder ret = new StringBuilder("String");
            foreach (JabTag tag in Tags) {
                ret.AppendLine(tag.ToString());
            }
            foreach (JabDoc doc in Docs) {
                ret.AppendLine(doc.ToString());
            }
            return ret.ToString();
        }

        public Database ToDatabase() {
            Database db = new Database();
            foreach (JabTag tag in Tags) {
                db.Pins.Add(tag.Name, tag.ToPin());
            }
            foreach (JabDoc d in Docs) {
                Reference r = d.ToReference(Tags);
                db.References.Add(r.Id, r);
            }
            return db;
        }
    }
}
